<include file="Public/head" />
<include file="Public/common_header" />
<div class="mian">
<include file="Public/sidebar" menu="cwgl.djq"  />
	<div class="mianR">
        <h3 class="cha">发放代金券</h3>
        <div class="grant">
            <div class="yuSuo clearfix">
                <input type="text" name="keyword" value="" placeholder="车商联系人/联系人电话" class="suoDian suoDian1"/>
                <input type="button" value="搜索" class="suoSou" style="width:80px;"/>
            </div>
        </div>
		<div class="listBox" id="listBox"></div>

    </div>
    <div class="clear"></div>
</div>
<div class="yunBei"></div>
<div class="tanShang tanShang6">
    <h3>发放代金券</h3>
    <ul class="daiJingW">
        <li class="clearfix"><span class="daiJing">代金券类型</span>
        <select name="coupon_type">
            <option value="">请选择代金券类型</option>
            <foreach name="coupon_type" item="item">
                <option value="{$item.coupon_type_id}">{$item.type_name}({$item.amount})</option>
            </foreach>
        </select>
        </li>
        <li class="clearfix"><span class="daiJing">券数量</span>
            <input type="text" name="num" value=""  placeholder="请输入发放数量"/>
        </li>

        <li class="clearfix">
            <input type="hidden" name="dealer_id" value=""/>
            <input type="button" value="确定" class="queding"/>
            <input type="button" value="取消" class="quxiao"/>
        </li>
    </ul>
</div>

<script type="text/javascript">
    get_list();
	function get_list(){
	    $.get("/Coupon/assign_list",{},function(data){
	    	$("#listBox").html(data);  
	    },"html");
	}

	function get_page(p){
	    $.get("/Coupon/assign_list", {'p':p}, function(data){
	    	$("#listBox").html(data);
	    },"html");
	}
	$('.suoSou').on('click',function(){
        var url = '/Coupon/assign_list';
        var keyword = $('input[name=keyword]').val();
        if(keyword !=""){
            url += '/keyword/'+encodeURIComponent(keyword);
        }
        //console.log(url)
        $.get(url,function(data){
   	    	$("#listBox").html(data);
   	    },"html");
    });
    $('.queding').on('click',function(){
        var dealer_id = $('input[name=dealer_id]').val();

        if(dealer_id ==''){
            shibai_alert1('车商ID不能为空，请联系管理员');
            return ;
        }
        var coupon_type_id = $('select[name=coupon_type]').val();

        if(coupon_type_id ==''){
            shibai_alert1('代金券类型不能为空');
            return ;
        }
        var num = $('input[name=num]').val();
        if(num<1){
            shibai_alert1('发放数量必须是大于0的整数');
            return ;
        }
        var param = {
            'dealer_id':dealer_id,
            'coupon_type_id':coupon_type_id,
            'num':num
        };
        confirm_alert('<div style="color:red">确定？</div>',confirm);
        function confirm(){
            $('.determine').click(function(){
                colse_hide();
                do_assign();

            });
        }
        function do_assign(){
            $.post('/Coupon/do_assign_coupon',param,function(data){
                if(data.code=='200'){
                    $('.tanShang6').hide();
                    btn_alert(data.msg);
                    location.reload() 
                }else{
                    shibai_alert1(data.msg)

                }
            },'json');
        }

    })


</script>
<include file="Public/foot" />